<template>
  <div>
    <h1>侦听器</h1>
    <input type="text" v-model.lazy="uname">
    <span>{{ msg }}</span>
  </div>
</template>

<script>
import axios from 'axios'

export default {
data() {
  return {
    uname: '小鱼卷',
    msg: ''
  }
},
watch: {
  // 函数写法
  // uname (newVal, oldVal) {
  //   console.log(newVal, oldVal)
  // }

  // 对象写法
  uname: {
    async handler (newVal) {
      const {data:res} = await axios.get('http://www.itcbc.com:3006/api/finduser/' + newVal)
      this.msg = res.message
    }
  }
}
}
</script>

<style>

</style>